import 'package:flutter/material.dart';
import 'package:online_study/bean/category.dart';
import 'package:online_study/theme/colors.dart';
import 'package:online_study/theme/size.dart';

class CategoryListPage extends StatefulWidget {
  List<Category> list;

  CategoryListPage(this.list);

  @override
  _CategoryListPageState createState() => _CategoryListPageState(list);
}

class _CategoryListPageState extends State<CategoryListPage> {
  List<Category> list;
  var _currentIndex = 0;
  var _choicedBgColor = ThemeColor.color1485EE;
  var _bgColor = ThemeColor.colorPagerBg;
  var _choicedTextColor = ThemeColor.colorWhite;
  var _textColor = ThemeColor.color333333;

  _CategoryListPageState(this.list);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ThemeSize.height84,
      height: double.infinity,
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
            child: Container(
              alignment: Alignment.center,
              height: ThemeSize.height48,
              color: _currentIndex == index ? _choicedBgColor : _bgColor,
              child: Text(list[index].categoryTitle,
                  style: TextStyle(
                      color: _currentIndex == index
                          ? _choicedTextColor
                          : _textColor,
                      fontSize: ThemeSize.sp13)),
            ),
            onTap: () {
              _currentIndex = index;
              setState(() {});
            },
          );
        },
        itemCount: list.length,
        // physics: NeverScrollableScrollPhysics(),
        shrinkWrap: true,
      ),
    );
  }
}
